import * as echarts from '../ec-canvas/echarts';
import _ from '../../utils/underscore';
//日
function setOption(chart, xname, lowMotion, inMotion, highMotion) {
    const option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        legend: {
            data: ['低活动强度', '中活动强度', '高活动强度'],
            align: 'left',
            left: 10,
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            // data:xname
            data: ['00点', '01点', '02点', '03点', '04点', '05点', '06点', '07点', '08点', '09点', '10点', '11点', '12点', '13点', '14点', '15点', '16点', '17点', '18点', '19点', '20点', '21点', '22点', '23点']
        },
        yAxis: {
            type: 'value',
        },
        series: [
            {
                name: '低强度',
                type: 'bar',
                stack: '总量',
                data: lowMotion,
                color: '#F6B92B'
            },
            {
                name: '中强度',
                type: 'bar',
                stack: '总量',
                data: inMotion,
                color: '#F99225'
            },
            {
                name: '高强度',
                type: 'bar',
                stack: '总量',
                data: highMotion,
                color: '#F8C8C5'
            },
        ],
        animation: false,
    };

    chart.setOption(option);
    return chart;
}
/**
 * 周假数据
 */
function setWeekOption(chart, xname, lowMotion, inMotion, highMotion) {
    const option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        legend: {
            data: ['低活动强度', '中活动强度', '高活动强度'],
            align: 'left',
            left: 10
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
            // data:xname
        },
        yAxis: {
            type: 'value',
        },
        series: [
            {
                name: '低强度',
                type: 'bar',
                stack: '总量',
                data: lowMotion,
                color: '#F6B92B'
            },
            {
                name: '中强度',
                type: 'bar',
                stack: '总量',
                data: inMotion,
                color: '#F99225'
            },
            {
                name: '高强度',
                type: 'bar',
                stack: '总量',
                data: highMotion,
                color: '#F6541E'
            },
        ],
        animation: false,
    };
    chart.setOption(option);
    return chart;
}
/**
 * 月假数据
 */
function setMonthOption(chart, xname, lowMotion, inMotion, highMotion) {
    const option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        legend: {
            data: ['低活动强度', '中活动强度', '高活动强度'],
            align: 'left',
            left: 10,

        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            data: xname
        },
        yAxis: {
            type: 'value',
        },
        series: [
            {
                name: '低强度',
                type: 'bar',
                stack: '总量',
                data: lowMotion,
                color: '#F6B92B'
            },
            {
                name: '中强度',
                type: 'bar',
                stack: '总量',
                data: inMotion,
                color: '#F99225'
            },
            {
                name: '高强度',
                type: 'bar',
                stack: '总量',
                data: highMotion,
                color: '#F6541E'
            },
        ],
        animation: false,
    };

    chart.setOption(option);
    return chart;
}
// data/ShowData.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        dataList: [
            {
                name: '日',
                isChoose: true
            }, {
                name: '周',
                isChoose: false
            }, {
                name: '月',
                isChoose: false
            }
        ],
        nowDate: '2018年7月22日-7月29日',
        nowDay: 29,
        nowWeekDay: 7,
        chooseIndex: 0,
        changeIndex: 0,  //用户点击上一步和下一步总计的操作，-3则代表在当前时间单位前跳3个时间单位，5则代表在当前时间单位后跳5个时间单位，0则无操作
        lowMotion: [],// 低强度
        inMotion: [],// 中强度
        highMotion: [], // 高强度
        deviceDatas: [],
        ec: {
            lazyLoad: true// 懒加载 柱状图
        },
        HighMotionTime: 0,
        MediumMotionTime: 0,
        LowMotionTime: 0,
        Step: 0,
        StepKM: 0,
        QuiteTime: 0
    },
    chooseData: function (e) {
        this.data.changeIndex = 0;
        let index = e.target.dataset.index;
        let dataList = this.data.dataList;
        for (let i = 0, len = dataList.length; i < len; i++) {
            dataList[i].isChoose = false;
        }
        dataList[index].isChoose = true;
        this.setData({
            dataList: dataList,
            chooseIndex: index
        });
        this.getNowDate(index);
        switch (index) {
            case 0:
                this.changeDayTime(0);
                break;
            case 1:
                this.changeWeekTime(1);
                break;
            case 2:
                this.changeMonthTime(2);
                break;
            
        }
    },
    //获取当前时间
    getNowDate: function (index) {
        //当下时间
        let nowTime = new Date();
        let nowMonth = nowTime.getMonth() + 1;
        let nowYear = nowTime.getFullYear();
        let nowDay = nowTime.getDate();
        let sevenDayLatyTime = new Date(nowTime.getTime() + 24 * 7 * 60 * 60 * 1000);
        let sevenDayLatyMonth = sevenDayLatyTime.getMonth() + 1;
        let sevenDayLatyDay = sevenDayLatyTime.getDate();
        this.handleNowDate(index, nowYear, nowMonth, nowDay, sevenDayLatyMonth, sevenDayLatyDay);
    },
    //变动以日为单位的时间
    changeDayTime: function (index) {
        wx.showLoading({
            title: '请稍等...',
        });
        let nowTime = new Date(new Date().getTime() + (this.data.changeIndex * 24) * 60 * 60 * 1000);
        let nowMonth = nowTime.getMonth() + 1;
        let nowYear = nowTime.getFullYear();
        let nowDay = nowTime.getDate();
        this.handleNowDate(index, nowYear, nowMonth, nowDay);
        this.data.lowMotion = this.handREQData('h', nowTime).lowMotionArr;
        this.data.inMotion = this.handREQData('h', nowTime).mediumMotionArr;
        this.data.highMotion = this.handREQData('h', nowTime).highMotionArr;
        let xname = this.handREQData('h', nowTime).xname;
        this.ecComponent.init((canvas, width, height) => {
            // 获取组件的 canvas、width、height 后的回调函数
            const chart = echarts.init(canvas, null, {
                width: width,
                height: height
            });

            setOption(chart, xname, this.data.lowMotion, this.data.inMotion, this.data.highMotion);
            // 将图表实例绑定到 this 上，可以在其他成员函数（如 dispose）中访问
            this.chart = chart;
            wx.hideLoading();
            // 注意这里一定要返回 chart 实例，否则会影响事件处理等
            return chart;
        });
       
    },
    //变动已周为单位的时间
    changeWeekTime: function (index) {
        wx.showLoading({
            title: '请稍等...',
        });
        let nowTime = new Date(new Date().getTime() + (this.data.changeIndex * 24 * 7) * 60 * 60 * 1000);
        let nowMonth = nowTime.getMonth() + 1;
        let nowYear = nowTime.getFullYear();
        let nowDay = nowTime.getDate();
        let sevenDayLatyTime = new Date(nowTime.getTime() + 24 * 7 * 60 * 60 * 1000);
        let sevenDayLatyMonth = sevenDayLatyTime.getMonth() + 1;
        let sevenDayLatyDay = sevenDayLatyTime.getDate();
        this.handleNowDate(index, nowYear, nowMonth, nowDay, sevenDayLatyMonth, sevenDayLatyDay);

        this.data.lowMotion = this.handREQData('w', nowTime, sevenDayLatyTime).lowMotionArr;
        this.data.inMotion = this.handREQData('w', nowTime, sevenDayLatyTime).mediumMotionArr;
        this.data.highMotion = this.handREQData('w', nowTime, sevenDayLatyTime).highMotionArr;
        let xname = this.handREQData('w', nowTime).xname;
        this.ecComponent.init((canvas, width, height) => {
            // 获取组件的 canvas、width、height 后的回调函数
            const chart = echarts.init(canvas, null, {
                width: width,
                height: height
            });
            setWeekOption(chart, xname, this.data.lowMotion, this.data.inMotion, this.data.highMotion);
            // 将图表实例绑定到 this 上，可以在其他成员函数（如 dispose）中访问
            this.chart = chart;
            wx.hideLoading();
            // 注意这里一定要返回 chart 实例，否则会影响事件处理等
            return chart;
        });
        // wx.hideLoading();
    },
    //变动以月为单位的时间
    changeMonthTime: function (index) {
        wx.showLoading({
            title: '请稍等...',
        });
        let nowTime = new Date(new Date().getTime() + (this.data.changeIndex * 24 * 30) * 60 * 60 * 1000);
        let nowMonth = nowTime.getMonth() + 1;
        let nowYear = nowTime.getFullYear();
        this.handleNowDate(index, nowYear, nowMonth);
        let xname = this.handREQData('y', nowTime).xname;

        this.data.lowMotion = this.handREQData('y', nowTime).lowMotionArr;
        this.data.inMotion = this.handREQData('y', nowTime).mediumMotionArr;
        this.data.highMotion = this.handREQData('y', nowTime).highMotionArr;

        this.ecComponent.init((canvas, width, height) => {
            // 获取组件的 canvas、width、height 后的回调函数
            const chart = echarts.init(canvas, null, {
                width: width,
                height: height
            });
            setMonthOption(chart, xname, this.data.lowMotion, this.data.inMotion, this.data.highMotion);
            // 将图表实例绑定到 this 上，可以在其他成员函数（如 dispose）中访问
            this.chart = chart;
            wx.hideLoading();
            // 注意这里一定要返回 chart 实例，否则会影响事件处理等
            return chart;
        });
        // wx.hideLoading();
    },
    //变动以年为单位的时间
    changeYearTime: function (index) {
        let nowTime = new Date();
        let nowYear = nowTime.getFullYear() + this.data.changeIndex;
        this.handleNowDate(index, nowYear);
    },
    //处理当前时间
    handleNowDate: function (index, nowYear, nowMonth, nowDay, sevenDayLatyMonth, sevenDayLatyDay) {
        let finalDate = '';
        switch (index) {
            case 0:
                finalDate = `${nowYear}年${nowMonth}月${nowDay}日`;
                break;
            case 1:
                finalDate = `${nowYear}年${nowMonth}月${nowDay}日-${sevenDayLatyMonth}月${sevenDayLatyDay}日`;
                break;
            case 2:
                finalDate = `${nowYear}年${nowMonth}月`;
                break;
        }
        this.setData({
            nowDate: finalDate,
        })
    },
    //点击向前跳时间
    prevTime: function () {
        this.data.changeIndex--;
        switch (this.data.chooseIndex) {
            case 0:
                this.changeDayTime(0);
                break;
            case 1:
                this.changeWeekTime(1);
                break;
            case 2:
                this.changeMonthTime(2);
                break;
        }
    },
    //点击向后跳时间
    nextTime: function () {
        this.data.changeIndex++;
        switch (this.data.chooseIndex) {
            case 0:
                this.changeDayTime(0);
                break;
            case 1:
                this.changeWeekTime(1);
                break;
            case 2:
                this.changeMonthTime(2);
                break;
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // 获取组件
        this.ecComponent = this.selectComponent('#mychart-dom-bar');
        this.changeDayTime(0);
        // this.changeDayTime
    },
    dayDataSet() {
        var that = this;
        wx.showLoading({
            title: '请稍等...',
        });
        // 1、拿到当天的数据 处理 展示到柱状图中
        try {
            var date = new Date();
            var dayKey = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
            var value = wx.getStorageSync(dayKey);
            if (value) {
                this.data.deviceDatas = value;
            }
        } catch (e) {
            console.log('获取数据异常');
        };
        // 切换统计图
        this.data.lowMotion = [];
        this.data.inMotion = [];
        this.data.highMotion = [];
        for (let i = 0; i < this.data.nowWeekDay; i++) {
            if (i == this.data.nowWeekDay) {
                this.data.lowMotion[i] = 25;
                this.data.inMotion[i] = 26;
                this.data.highMotion[i] = 10;
            } else {
                var randomLow = Math.floor(Math.random() * 300 + 180);
                var randomIn = Math.floor(Math.random() * 380 + 100);
                var randomHigh = Math.floor(Math.random() * 450 + 30);
                this.data.lowMotion[i] = randomLow;
                this.data.inMotion[i] = randomIn;
                this.data.highMotion[i] = randomHigh;
            }
        }
        this.ecComponent.init((canvas, width, height) => {
            // 获取组件的 canvas、width、height 后的回调函数
            const chart = echarts.init(canvas, null, {
                width: width,
                height: height
            });
            setWeekOption(chart, this.data.lowMotion, this.data.inMotion, this.data.highMotion);
            // 将图表实例绑定到 this 上，可以在其他成员函数（如 dispose）中访问
            this.chart = chart;
            // 注意这里一定要返回 chart 实例，否则会影响事件处理等
            return chart;
        });
        wx.hideLoading();
    },
    handREQData(type, start, end) {
        // let reqData = { "Step": 1905, "Calorie": 165, "DayDatas": [{ "CreateTime": "2018-09-13T00:03:58.8224285+08:00", "HighMotion": 12, "HighMotionTime": 4, "MediumMotion": 40, "MediumMotionTime": 40, "LowMotion": 107, "LowMotionTime": 93 }, { "CreateTime": "2018-09-12T00:03:58.8224285+08:00", "HighMotion": 12, "HighMotionTime": 4, "MediumMotion": 40, "MediumMotionTime": 40, "LowMotion": 107, "LowMotionTime": 93 }, { "CreateTime": "2018-09-11T00:03:58.8224285+08:00", "HighMotion": 12, "HighMotionTime": 4, "MediumMotion": 40, "MediumMotionTime": 40, "LowMotion": 107, "LowMotionTime": 93 }], "HourDatas": [{ "CreateTime": "2018-09-13T00:03:58.8224285+08:00", "HourSign": 8, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-13T00:03:58.8224285+08:00", "HourSign": 12, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-13T00:03:58.8224285+08:00", "HourSign": 16, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-13T00:03:58.8224285+08:00", "HourSign": 20, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-12T00:03:58.8224285+08:00", "HourSign": 8, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-12T00:03:58.8224285+08:00", "HourSign": 12, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-12T00:03:58.8224285+08:00", "HourSign": 16, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-12T00:03:58.8224285+08:00", "HourSign": 20, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-11T00:03:58.8224285+08:00", "HourSign": 8, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-11T00:03:58.8224285+08:00", "HourSign": 12, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-11T00:03:58.8224285+08:00", "HourSign": 16, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }, { "CreateTime": "2018-09-11T00:03:58.8224285+08:00", "HourSign": 20, "HighMotion": 2, "HighMotionTime": 2, "MediumMotion": 20, "MediumMotionTime": 20, "LowMotion": 31, "LowMotionTime": 30 }] }
        let highMotionTime = 0;
        let mediumMotionTime = 0;
        let lowMotionTime = 0;
        let reqData=wx.getStorageSync('ReqData');
        let formatTime = function (times) {
            if (!times) {
                return '0分钟'
            }
            var day = parseInt(times / 60 / 24);
            var hour = parseInt(times / 60 % 24);
            var min = parseInt(times % 60);
            let StatusMinute = "";
            if (day > 0) {
                StatusMinute = day + "天";
            };
            if (hour > 0) {
                StatusMinute += hour + "小时";
            };
            if (min > 0) {
                StatusMinute += parseFloat(min) + "分钟";
            };
            return StatusMinute;

        };
       
        let dataTime = function (time) {
            let dt = new Date(time);
            let times = dt.getTime();
            return times
        }
        console.log(reqData)
        if (type == 'h') {
            let hourArry = [];
            let hourDatas = reqData.HourDatas;
            let dataTime = function (time) {
                let dt = new Date(time);
                let times = dt.getTime();
                return times
            }
           

            hourDatas.forEach(function (item, index) {
                let d = new Date(start);
                let e = new Date(start);
                let startHour = d.setHours(0, 0, 0);
                let endHour = e.setHours(23, 59, 59)
                let startTime = dataTime(startHour);
                let endTime = dataTime(endHour);
                let times = dataTime(item.CreateTime);

                if (times > startTime && times < endTime) {
                    hourArry.push(item);
                }
            });
            if(!hourArry){
                return {
                    lowMotionArr: 0,
                    mediumMotionArr: 0,
                    highMotionArr: 0
                }
            }
            hourArry.forEach(function (item, index) {
                highMotionTime += parseInt(item.HighMotionTime);
                mediumMotionTime += parseInt(item.MediumMotionTime);
                lowMotionTime += parseInt(item.LowMotionTime);
            });
            this.setData({
                QuiteTime: formatTime(1 * 24 * 60 - (highMotionTime + mediumMotionTime + lowMotionTime)),
                HighMotionTime: formatTime(highMotionTime),
                MediumMotionTime: formatTime(mediumMotionTime),
                LowMotionTime: formatTime(lowMotionTime),
                Step: reqData.Step,
                StepKM: reqData.Step * 0.5 / 1000
            });
            let hourArrys = [];
            for (var n = 0; n < hourArry.length; n++) {
                let item = hourArry[n];
                hourArrys[new Date(item.CreateTime).getHours()] = item;
            };
            // console.log(hourArrys)
            let sortBy = hourArrys;
            let lowMotionArr = []; //低
            let mediumMotionArr = []; //中
            let highMotionArr = []; //高
            lowMotionArr = _.pluck(sortBy, "LowMotion");
            highMotionArr = _.pluck(sortBy, "HighMotion");
            mediumMotionArr = _.pluck(sortBy, "MediumMotion");
            return {
                lowMotionArr: lowMotionArr,
                mediumMotionArr: mediumMotionArr,
                highMotionArr: highMotionArr
            }
        } else if (type == 'w') {
            let hourArry = [];
            let DayDatas = reqData.DayDatas;
            let dataTime = function (time) {
                let dt = new Date(time);
                let times = dt.getTime();
                return times
            };
            DayDatas.forEach(function (item, index) {
                let d = new Date(start);
                let e = new Date(start);

                var now = d;
                var nowTime = now.getTime();
                var day = now.getDay();
                var oneDayTime = 24 * 60 * 60 * 1000;
                var MondayTime = nowTime - (day - 1) * oneDayTime;//显示周一
                var SundayTime = nowTime + (7 - day) * oneDayTime;//显示周日

                let times = dataTime(item.CreateTime);

                if (times > MondayTime && times < SundayTime) {
                    hourArry.push(item);

                }
            });
            if(!hourArry){
                return {
                    lowMotionArr: 0,
                    mediumMotionArr: 0,
                    highMotionArr: 0
                }
            };
            hourArry.forEach(function (item, index) {
                highMotionTime += parseInt(item.HighMotionTime);
                mediumMotionTime += parseInt(item.MediumMotionTime);
                lowMotionTime += parseInt(item.LowMotionTime);
            });

            this.setData({
                QuiteTime: formatTime(7 * 24 * 60 - (highMotionTime + mediumMotionTime + lowMotionTime)),
                HighMotionTime: formatTime(highMotionTime),
                MediumMotionTime: formatTime(mediumMotionTime),
                LowMotionTime: formatTime(lowMotionTime),
                Step: reqData.Step,
                StepKM: reqData.Step * 0.5 / 1000
            })
            let hourArrys = [];
            for (var n = 0; n < hourArry.length; n++) {
                let item = hourArry[n];
                hourArrys[new Date(item.CreateTime).getDay() - 1] = item;
            };
            let sortBy = hourArrys;
            let xname = _.pluck(sortBy, "CreateTimeWeek");

            let lowMotionArr = []; //低
            let mediumMotionArr = []; //中
            let highMotionArr = []; //高
            lowMotionArr = _.pluck(sortBy, "LowMotion");
            highMotionArr = _.pluck(sortBy, "HighMotion");
            mediumMotionArr = _.pluck(sortBy, "MediumMotion");

            return {
                xname: xname,
                lowMotionArr: lowMotionArr,
                mediumMotionArr: mediumMotionArr,
                highMotionArr: highMotionArr
            }
        } else if (type == 'y') {
            // 获取当前月的最后一天
            let hourArry = [];
            let getCurrentMonthLast = function (start) {
                var date = new Date(start);
                var currentMonth = date.getMonth();
                var nextMonth = ++currentMonth;
                var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
                var oneDay = 1000 * 60 * 60 * 24;
                return new Date(nextMonthFirstDay - oneDay);
            }
            let dayDatas = reqData.DayDatas;
            let selfDays = 0;
            dayDatas.forEach(function (item, index) {
                let d = new Date(start);
                let e = new Date(getCurrentMonthLast(start));
                selfDays = e.getDate();
                d.setDate(1);
                d.setHours(0, 0, 0);
                let startHour = d.setHours(0, 0, 0);
                let endHour = e.setHours(23, 59, 59)

                let startTime = dataTime(startHour);
                let endTime = dataTime(endHour);
                let times = dataTime(item.CreateTime);

                if (times > startTime && times < endTime) {
                    hourArry.push(item);
                }
            });
            if(!hourArry){
                return {
                    lowMotionArr: 0,
                    mediumMotionArr: 0,
                    highMotionArr: 0
                }
            };
            hourArry.forEach(function (item, index) {
                highMotionTime += parseInt(item.HighMotionTime);
                mediumMotionTime += parseInt(item.MediumMotionTime);
                lowMotionTime += parseInt(item.LowMotionTime);
            });
            this.setData({
                QuiteTime: formatTime(selfDays * 24 * 60 - (highMotionTime + mediumMotionTime + lowMotionTime)),
                HighMotionTime: formatTime(highMotionTime),
                MediumMotionTime: formatTime(mediumMotionTime),
                LowMotionTime: formatTime(lowMotionTime),
                Step: reqData.Step,
                StepKM: reqData.Step * 0.5 / 1000
            })
            let hourArrys = [];
            for (var n = 0; n < hourArry.length; n++) {
                let item = hourArry[n];
                hourArrys[new Date(item.CreateTime).getDate() - 1] = item;
            };
            let sortBy = hourArrys;
            let xname;
            let days = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28']
            if (selfDays == 31) {
                days[28] = '29';
                days[29] = '30';
                days[30] = '31';
                xname = days;
            } else if (selfDays == 30) {
                days[28] = '29';
                days[29] = '30';
                xname = days;
            } else {
                xname = days;
            };
            let lowMotionArr = []; //低
            let mediumMotionArr = []; //中
            let highMotionArr = []; //高
            lowMotionArr = _.pluck(sortBy, "LowMotion");
            highMotionArr = _.pluck(sortBy, "HighMotion");
            mediumMotionArr = _.pluck(sortBy, "MediumMotion");
            return {
                xname: xname,
                lowMotionArr: lowMotionArr,
                mediumMotionArr: mediumMotionArr,
                highMotionArr: highMotionArr
            }
        }
    }

})